package com.mapull.tree;

import java.util.*;

/**
 * 层序输出二叉树
 * @author mapull
 * @create 2022-05-06
 */
public class BSFPrintTree {

    public static void main(String[] args) {
        System.out.println(isValid("{{}}"));
    }

    public static boolean isValid(String s) {
        Stack<Character> stack = new Stack<>();
        char[] chars = s.toCharArray();
        for(char c : chars){
            if(c == '{' || c == '[' || c == '('){
                stack.push(c);
            }else {
                char cc = stack.pop();
                if(('{' == cc && c != '}') || ('(' == cc && c != ')') || ('[' == cc && c != ']')){
                    return false;
                }
            }
        }
        return true;

    }


    private int[] levelOrder(TreeNode root){
        if(root == null){
            return new int[0];
        }
        Queue<TreeNode> queue = new LinkedList<>();
        queue.add(root);
        List<Integer> list = new ArrayList<>();
        while(!queue.isEmpty()){
            TreeNode node = queue.poll();
            list.add(node.val);
            if(node.left != null){
                queue.add(node.left);
            }
            if(node.right != null){
                queue.add(node.right);
            }
        }
        int[] res = new int[list.size()];
        for(int i = 0; i< list.size(); i++){
            res[i] = list.get(i);
        }
        return res;
    }


    class TreeNode{
        int val;
        TreeNode left;
        TreeNode right;
        TreeNode(){}
        TreeNode(int val){
            this.val = val;
        }
        TreeNode(int val, TreeNode l, TreeNode r){
            this.val = val;
            this.left = l;
            this.right = r;
        }
    }
}
